package com.lanqiao.companymanage.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lanqiao.companymanage.entity.AssetClass;
import com.lanqiao.companymanage.service.AssetClassService;
import com.lanqiao.companymanage.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 何小棍
 * 资产类别管理与添加
 */
@RestController
@RequestMapping("/assetClass")
@Api(tags = "资产类别管理")
public class AssetClassController {
    @Autowired
    AssetClassService assetClassService;

    /**
     * 分页查询
     */
    @GetMapping("/assetClassPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页数,默认第一页"),
            @ApiImplicitParam(name = "size", value = "每页显示条数，默认 10")})
    @ApiOperation(value = "分页查询")
    public Object assetClassPage(Page<AssetClass> assetClassPage) {
        Page<AssetClass> page = assetClassService.listPage(assetClassPage);
        return Result.success(page);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/selectById")
    @ApiOperation(value = "根据id查询")
    public Object selectById(Integer id) {
        AssetClass assetClass = assetClassService.selectById(id);
        if (assetClass == null) {
            return Result.err("找不到对应id的值");
        } else {
            return Result.success("查询成功", assetClass);
        }
    }

    /**
     * 资产类别添加
     * @param assetClass
     * @return
     */
    @PostMapping("/addAssetClass")
    @ApiOperation(value = "资产类别添加")
    public Object addAssetClass(AssetClass assetClass) {
        int i = assetClassService.addAssetClass(assetClass);
        if (i == 0) {
            return Result.err("添加失败");
        } else {
            return Result.success("添加成功", null);
        }
    }

    /**
     * 根据id删除
     */
    @GetMapping("/deletedById")
    @ApiOperation(value = "根据id删除")
    public Object deletedById(Integer id) {
        int i = assetClassService.deleteById(id);
        if (i == 0) {
            return Result.err("删除失败");
        } else {
            return Result.success("删除成功", null);
        }
    }

    /**
     * 根据id修改
     */
    @PostMapping("/updateAssetClass")
    @ApiOperation(value = "根据id修改")
    public Object updateAssetMess(AssetClass assetClass) {
        int i = assetClassService.updateAssetClass(assetClass);
        if (i == 0) {
            return Result.err("修改失败");
        } else {
            return Result.success("修改成功", null);
        }
    }


    /**
     * 查询全部类别
     */
    @GetMapping("/selectAll")
    @ApiOperation(value = "查询全部类别")
    public Result selectAll()  {
        List<AssetClass> depList = assetClassService.selectAll();
        return Result.success("查询成功",depList);
    }

}
